home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLSR106.ARJ / SETBUFFE.C < prev    next >
C/C++ Source or Header  |  1992-03-02  |  1KB  |  54 lines

  1. /* This is file SETBUFFE.C */
  2. /* This file may have been modified by DJ Delorie (Jan 1991).  If so,
  3. ** these modifications are Coyright (C) 1991 DJ Delorie, 24 Kirsten Ave,
  4. ** Rochester NH, 03867-2954, USA.
  5. */
  6.  
  7. /*
  8.  * Copyright (c) 1983 Regents of the University of California.
  9.  * All rights reserved.  The Berkeley software License Agreement
  10.  * specifies the terms and conditions for redistribution.
  11.  */
  12.  
  13. #if defined(LIBC_SCCS) && !defined(lint)
  14. static char sccsid[] = "@(#)setbuffer.c    5.2 (Berkeley) 3/9/86";
  15. #endif LIBC_SCCS and not lint
  16.  
  17. #include    <stdio.h>
  18.  
  19. setbuffer(iop, buf, size)
  20.     register FILE *iop;
  21.     char *buf;
  22.     int size;
  23. {
  24.     if (iop->_base != NULL && iop->_flag&_IOMYBUF)
  25.         free(iop->_base);
  26.     iop->_flag &= ~(_IOMYBUF|_IONBF|_IOLBF);
  27.     if ((iop->_base = buf) == NULL) {
  28.         iop->_flag |= _IONBF;
  29.         iop->_bufsiz = NULL;
  30.     } else {
  31.         iop->_ptr = iop->_base;
  32.         iop->_bufsiz = size;
  33.     }
  34.     iop->_cnt = 0;
  35. }
  36.  
  37. /*
  38.  * set line buffering for either stdout or stderr
  39.  */
  40. setlinebuf(iop)
  41.     register FILE *iop;
  42. {
  43.     char *buf;
  44.     extern char *malloc();
  45.  
  46.     fflush(iop);
  47.     setbuffer(iop, NULL, 0);
  48.     buf = malloc(BUFSIZ);
  49.     if (buf != NULL) {
  50.         setbuffer(iop, buf, BUFSIZ);
  51.         iop->_flag |= _IOLBF|_IOMYBUF;
  52.     }
  53. }
  54.